﻿using UnityEngine.Playables;
using FrameOperateSync;

namespace Pvp.Timeline
{
    /// <summary>
    /// 角色位移采样 （时间未对齐）
    /// </summary>
    public class RoleTransformBehaviour : BaseRolePlayableBehaviour
    {
        FPLibrary.Fix64 lastSampleTime = 0;
        private FPLibrary.Fix64 duration;
        public FPLibrary.FPPolyline xMovementLine;
        public FPLibrary.FPPolyline zMovementLine;

        public override void OnGraphStart(Playable playable)
        {
            base.OnGraphStart(playable);
            duration = playable.GetDuration();
        }

        public override void OnBehaviourPause(Playable playable, FrameData info)
        {
            base.OnBehaviourPause(playable, info);
        }

        public override void OnBehaviourPlay(Playable playable, FrameData info)
        {
            base.OnBehaviourPlay(playable, info);

            lastSampleTime = playable.GetTime();
        }

        public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            FPLibrary.Fix64 xdelta = 0, zdelta = 0;
            if (xMovementLine != null)
            {
                xdelta = xMovementLine.EvaluateDelta(lastSampleTime, (float)playable.GetTime());
            }
            if (zMovementLine != null)
            {
                zdelta = zMovementLine.EvaluateDelta(lastSampleTime, (float)playable.GetTime());
            }
            lastSampleTime = (float)playable.GetTime();

            //角色z轴
            // entity.transPosition.x += xdelta * FightDriver.DeltaTime * Rolexxx.Control.speed;
            // Rolexxx.Trans.position.z += zdelta * FightDriver.DeltaTime * Rolexxx.Control.speed;
        }
    }
}



